package com.feature.core.rabbitmq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnsCallback;

/**
 * 交换器无法根据路由键将消息路由到任何队列，RabbitMQ 会将消息返回给生产者，同时触发返回确认回调。
* @Description:
* @author wangzhiyue
* @date 2025/04/29 09:53:42
 */
public class LogReturnsCallback implements ReturnsCallback {

	private Logger logger = LoggerFactory.getLogger(getClass());

	@Override
	public void returnedMessage(ReturnedMessage returned) {
		MessageProperties messageProperties = returned.getMessage().getMessageProperties();
		String traceID = String.valueOf(messageProperties.getHeaders().get("traceID"));
		this.logger.error("消息发送失败状态提示,TRACEID:{},MSGID:{},replyCode:{},replyText:{},详情请查看数据分析系统。",
				new Object[] { traceID, messageProperties.getMessageId(), returned.getReplyCode(), returned.getReplyText() });
	}

}
